package com.zh.note.leetcode.greedy;

/**
 * @Author: zhanghuan
 * @date: 2023/7/9 14:51
 * @description: create it
 */
public class LC_860_lemonadeChange {

    public boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;
        int twenty = 0;
        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) { //账单是5，直接收下
                five++;
            }
            if (bills[i] == 10) { //账单是10，消耗一个5，增加一个10
                if (five == 0) {
                    return false;
                } else {
                    ten++;
                    five--;
                }
            }
            if (bills[i] == 20) { //账单是20，优先消耗一个10和一个5，如果不够，再消耗三个5
                if (ten > 0 && five > 0) {
                    twenty++;
                    ten--;
                    five--;
                } else if (five >= 3) {
                    five -= 3;
                    twenty++;
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}
